﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NJL.WebUsers
{
    public partial class AttractionsOrderOK : BasePage
    {
        private readonly NJL.BLL.NJL_BOOK bllBook = new BLL.NJL_BOOK();
        private readonly NJL.BLL.NJL_BOOK_ORDER bllBookOrder = new BLL.NJL_BOOK_ORDER();
        private readonly NJL.BLL.NJL_ATTRACTION bllAttr = new BLL.NJL_ATTRACTION();

        protected NJL.Model.NJL_BOOK modelBook;
        protected NJL.Model.NJL_BOOK_ORDER modelBookOrder;
        protected NJL.Model.NJL_ATTRACTION modelAttr;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        void bind()
        {
            modelBookOrder = bllBookOrder.GetModel(Request.QueryString["id"]);
            litqpr.Text = modelBookOrder.PICK_NAME;
            ltilxfs.Text = modelBookOrder.PICK_MOBILE;
            litydr.Text = modelBookOrder.BOOK_NAME;
            litydrlxfs.Text = modelBookOrder.PICK_MOBILE;
            litywrq.Text = string.Format("{0:yyyy-MM-dd}",modelBookOrder.VISIT_DATE);
            lttydzs.Text = modelBookOrder.TICKET_COUNT.ToString();
            litqpdd.Text = "景区现付";


            modelBook = bllBook.GetModel(modelBookOrder.NJL_BOOK_ID);

            if (modelBook != null)
            {
                litdpjj.Text = string.Format("{0:0}", modelBook.BACK_PRICE);
                litxfje.Text = string.Format("{0:0}", modelBookOrder.ORDER_TOTAL);
                modelAttr = bllAttr.GetModel(modelBook.TARGET_ID);
                if (modelAttr != null)
                {
                    litName.Text = modelAttr.ATTRACTION_NAME;
                    litName1.Text = modelAttr.ATTRACTION_NAME;
                }
            }

            string SMSContentToPicker = WEBSITE_NAME + "：订单号" + modelBookOrder.ID + "，" + modelBookOrder.VISIT_DATE.Value.ToString("MM月dd日") + "[" + modelAttr.ATTRACTION_NAME + "]" + modelBook.BOOK_NAME + " " + modelBookOrder.TICKET_COUNT + " 张预定成功，价格：" + modelBookOrder.ORDER_TOTAL.Value.ToString("#") + "元[" + (modelBookOrder.TYPE_CODE == "2" ? "景区现付" : "已在线支付") + "]，售票处报订单号取票。如有疑问请致电400-676-1998客服中心。";
            string SMSContentToCompany = WEBSITE_NAME + "：订单号" + modelBookOrder.ID + "，" + modelBookOrder.VISIT_DATE.Value.ToString("MM月dd日") + "[" + modelAttr.ATTRACTION_NAME + "]" + modelBook.BOOK_NAME + " " + modelBookOrder.TICKET_COUNT + " 张，价格：" + modelBookOrder.ORDER_TOTAL.Value.ToString("#") + "元[" + (modelBookOrder.TYPE_CODE == "2" ? "景区现付" : "在线支付") + "]。取票人：" + modelBookOrder.PICK_NAME + "(" + modelBookOrder.PICK_MOBILE + ")";

            if (modelBookOrder.PICK_MOBILE != modelBookOrder.BOOK_MOBILE)
            {
                SMSContentToPicker = WEBSITE_NAME + "：订单号" + modelBookOrder.ID + "，" + modelBookOrder.BOOK_NAME + "(" + modelBookOrder.BOOK_MOBILE + ")已为您成功预定" + modelBookOrder.VISIT_DATE.Value.ToString("MM月dd日") + "[" + modelAttr.ATTRACTION_NAME + "]" + modelBook.BOOK_NAME + " " + modelBookOrder.TICKET_COUNT + " 张，价格：" + modelBookOrder.ORDER_TOTAL.Value.ToString("#") + "元[" + (modelBookOrder.TYPE_CODE == "2" ? "景区现付" : "已在线支付") + "]，售票处报订单号取票。如有疑问请致电400-676-1998客服中心。";
                SMSContentToCompany = WEBSITE_NAME + "：订单号" + modelBookOrder.ID + "，" + modelBookOrder.VISIT_DATE.Value.ToString("MM月dd日") + "[" + modelAttr.ATTRACTION_NAME + "]" + modelBook.BOOK_NAME + " " + modelBookOrder.TICKET_COUNT + " 张，价格：" + modelBookOrder.ORDER_TOTAL.Value.ToString("#") + "元[" + (modelBookOrder.TYPE_CODE == "2" ? "景区现付" : "在线支付") + "]。取票人：" + modelBookOrder.PICK_NAME + "(" + modelBookOrder.PICK_MOBILE+")";
            }

            if (modelBookOrder.PICK_MOBILE.Length == 11)
            {
                int i = base.SendSMS(modelBookOrder.PICK_MOBILE, SMSContentToPicker);

                i = base.SendSMS(System.Configuration.ConfigurationManager.AppSettings["CompanySmsMobile"], SMSContentToCompany);
            }

            if (modelBookOrder.BOOK_EMAIL != null && modelBookOrder.BOOK_EMAIL != "")
            {
                //发送邮件
            }
        }
    }
}